#!/bin/bash  
  
# 检查是否提供了进程名作为参数  
if [ "$#" -ne 1 ]; then  
    echo "Usage: $0 <process_name>"  
    exit 1  
fi  
  
# 获取进程名参数  
process_name=$1  
  
# 使用pgrep获取进程PID  
pid=$(pgrep -o "$process_name")  
  
# 检查是否找到了PID  
if [ -z "$pid" ]; then  
    echo "No process found with name: $process_name"  
    exit 1  
fi  
  
# 死循环打印线程信息  
while true; do  
    echo "Threads for process $process_name (PID $pid):"  
    ps -Lf $pid  
    # 等待一段时间后再次打印，可以根据需要调整sleep的时间  
    sleep 1  
done